package com.avfh.netcard.service.impl;

import com.avfh.netcard.common.Result;
import com.avfh.netcard.model.Order;
import com.avfh.netcard.mapper.OrderMapper;
import com.avfh.netcard.model.User;
import com.avfh.netcard.service.IOrderService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wuhui
 * @since 2017-06-26
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Override
    public Page<Order> queryPage(Map<String, Object> data, Page<Order> page) {

//        String startTime = page.getCurrent() * 6;
//        String endTime = page.getc
//        data.put("startTime", endTime);
//        List<Order> list = this.queryPage(data);
//        page.setRecords(list);
        return page;
    }


    @Override
    public Map<String, String> createOrder(Map<String, Object> data) {
        Long packageId = Long.parseLong(data.get("packageId").toString());
        String packageName = data.get("packageName").toString();
        String ip = data.get("ip").toString();
        Double packCurrentPrice = Double.parseDouble(data.get("currentPrice").toString());
        Order order = new Order()
                .setAmount(packCurrentPrice)
                .setCreatedAt(new Date())
                .setDesc("微信支付-流量充值" + packageName)
                .setPackageId(packageId)
                .setStatus(1);
        order.insert();

        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("out_trade_no", order.getOrderId() + "");
        paramMap.put("total_fee", (int) (packCurrentPrice * 100) + "");
        paramMap.put("spbill_create_ip", ip);
        return paramMap;
    }

}
